package chapter08

import "fmt"

// counter -- squarer -- printer
func Pipeline1Main() {
	naturals := make(chan int)
	squares := make(chan int)

	// counter
	go func() {
		for x := 0; ; x++ {
			naturals <- x
		}
	}()
	// squarer
	go func() {
		for {
			x, ok := <-naturals
			if !ok {
				break
			}
			squares <- x * x
		}
		close(squares)
	}()
	// printer(挂在 主goroutine上)
	for {
		fmt.Println(<-squares)
	}
}
